import { Component,  Injector, ViewChild, EventEmitter, Output } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import {
    StockZT_BorrowBillItemServiceProxy
} from '@shared/service-proxies/stock-service-proxies';
import * as _ from 'lodash';
import { ModalDirective } from 'ngx-bootstrap';
import { Base_UserCardDto } from '@shared/service-proxies/stock-service-proxies';

@Component({
    templateUrl: './tool-return-modal.component.html',
    animations: [appModuleAnimation()],
    selector: 'toolReturnModal'
})
export class ToolReturnModalComponent extends AppComponentBase   {
    constructor(
        injector: Injector,
        private _billService: StockZT_BorrowBillItemServiceProxy
    ) {
        super(injector);
    }

    @ViewChild('createOrEditModal') modal: ModalDirective;

    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
   
 
    saving = false;
    closed = false;
    active = false;
    userName='';
    cardno;
    usercard:Base_UserCardDto;
    id;
    show(usercard,id): void {
        this.usercard=usercard;
        this.id=id;
      //  this.active = true;
        this.closed = false;
        this.modal.show();

    }

    close(): void {
      //  this.active = false;
        this.modal.hide();
    }

    onHidden(event) {
        this.closed = true;
    }


    save() {
        // console.log(this.id);
        // console.log(this.cardno);
        // console.log(this.usercard);
        if(this.cardno<=0){
            this.message.warn('归还数量必须大于0');
            return;
        }
       this._billService.returnBorrowBillItem(this.id,this.cardno,this.usercard).subscribe(result=>{
        console.log(result);
        this.notify.success(this.l('提交成功'));
        this.modalSave.emit(this.id);
        this.close();
       })
    }






}
